import SwiftUI

struct CustomAlertView: View {
    @Binding var isPresented: Bool
    var isSingleButton: Bool = false

    var icon: String = "exclamationmark.triangle.fill"
    var iconColor: Color = .yellow
    var title: String = "提示"
    var message: String
    var closeButtonText: String = "取消"
    var confirmButtonText: String = "同意"
    var onClose: (() -> Void)? = nil
    var onConfirm: () -> Void = {}

    var body: some View {
        ZStack {
            Color.black.opacity(0.35)
                .ignoresSafeArea()

            VStack(spacing: AppSpacing.l) {
                HStack(spacing: AppSpacing.m) {
                    Image(systemName: icon)
                        .foregroundStyle(iconColor)
                        .font(.system(size: 22))
                    Text(title)
                        .font(.headline)
                        .foregroundStyle(.primary)
                }

                Text(message)
                    .font(AppFont.body)
                    .foregroundStyle(.secondary)
                    .multilineTextAlignment(.center)
                    .padding(.horizontal, AppSpacing.l)

                HStack(spacing: AppSpacing.m) {
                    if !isSingleButton {
                        Button(closeButtonText) {
                            onClose?()
                            withAnimation { isPresented = false }
                        }
                        .foregroundStyle(.white)
                        .frame(maxWidth: .infinity)
                        .padding(.vertical, 12)
                        .background(
                            RoundedRectangle(cornerRadius: AppRadius.m, style: .continuous).fill(.gray)
                        )
                    }

                    Button(confirmButtonText) {
                        onConfirm()
                        withAnimation { isPresented = false }
                    }
                    .foregroundStyle(.white)
                    .frame(maxWidth: .infinity)
                    .padding(.vertical, 12)
                    .background(
                        RoundedRectangle(cornerRadius: AppRadius.m, style: .continuous).fill(Color.accentColor)
                    )
                }
            }
            .padding(AppSpacing.xl)
            .background(
                RoundedRectangle(cornerRadius: AppRadius.l, style: .continuous)
                    .fill(Color(.systemBackground))
                    .shadow(radius: 16, y: 4)
            )
            .padding(.horizontal, 40)
        }
        .transition(.opacity.combined(with: .scale))
    }
}


